/*
 * @lc app=leetcode.cn id=1437 lang=typescript
 *
 * [1437] 是否所有 1 都至少相隔 k 个元素
 */

// @lc code=start
function kLengthApart(nums: number[], k: number): boolean {
    // 找到前置 0 并忽略
    let start = 0;
    while (nums[start] !== 1 && start < nums.length) {
        start++;
    }

    let now = k;
    for (let i = start + 1; i < nums.length; i++) {
        const element = nums[i];
        if (element === 1) {
            if (now > 0) return false;
            now = k;
        } else {
            now--;
        }
    }
    return true;
}
// @lc code=end
